package cn.wizzer.app.web.commons.utils;

import cn.wizzer.app.sys.modules.services.SysIpWhiteListService;
import cn.wizzer.app.sys.modules.services.SysParamService;
import cn.wizzer.framework.util.IPTableUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

@IocBean(name =  "iPTableUtil")
public class IPWhiteListUtilImpl extends IPTableUtil {
    @Reference
    @Inject
    private SysIpWhiteListService ipWhiteListService;
    @Reference
    @Inject
    private SysParamService paramService;

    @Override
    public boolean contains(String ip) {
        if (paramService.fetch().isOnlyWhiteList()) {
            ipTables = ipWhiteListService.queryAll();
            return !ipTables.contains(ip);
        }
        return false;
    }
}
